<template>
  <div id="login">
    <div class="background">
    <img :src="imgSrc" width="100%" height="100%" alt="" />
</div>
    <div class="content">
      <img src="../assets/img/logo.png" alt="">
    <h1 style="font-family: cursive;
    color: aliceblue;
    font-size: xxx-large">前辈说</h1>
    <h5 style="font-family: cursive;font-size: large;">标记我的学习</h5>
    <van-form @submit="onSubmit">
      <van-field
        v-model="username"
        name="用户名"
        label="用户名"
        placeholder="用户名"
        :rules="[{ required: true, message: '请填写用户名' }]"
      />
      <van-field
        v-model="password"
        type="password"
        name="密码"
        label="密码"
        placeholder="密码"
        :rules="[{ required: true, message: '请填写密码' }]"
      />
      <div style="margin: 16px">
        <van-button round block type="info" native-type="submit"
          style="top: 10px">提交</van-button
        >
      </div>
    </van-form>
    <h5 style="margin-top: 50px;">登录代表同意《用户协议》《隐私政策》</h5>
    </div>
  </div>
</template>

<script>
import axios from "axios";
import { Toast } from "vant";
export default {
  data() {
    return {
      username: "",
      password: "",
      imgSrc:require('../assets/img/nav7.png')
    };
  },
  methods: {
    onSubmit() {
      axios
        .post(
           "/api/demo/web2/public/index.php/api/login/dologin.html?username=" +
            this.username +
            "&password=" +
            this.password
        )
        .then((res) => {
          if (res.data.code == 200) {
            console.log(res.data.data.id);
            localStorage.setItem("login_username", res.data.data.username);
            localStorage.setItem("login_user_id", res.data.data.id);
            localStorage.setItem("login_user_state", res.data.data.state);
            localStorage.setItem("login_user_img", res.data.data.user_img);
            Toast.success("登录成功");
            // this.$store.commit("updateLogin", true);
            this.$router.push("./home");
            } else {
              Toast.fail("用户名或密码错误");
          }
          console.log(res);
        });
      console.log("login");
    },
  },
};
</script>

<style lang="scss" scoped>
body {
  margin: 0;
}
.van-form {
  margin-top: 100px;
}
.van-field__control {
  height: 30px;
}
.van-cell.van-field {
  background: bottom;
}
.van-button {
  background: lightpink;
}
.background{
   width:100%;  
    height:100%;  /**宽高100%是为了图片铺满屏幕 */
    z-index:-1;
    position: absolute;
}
.content img{
      margin-top: 80px;
}
</style>
